//
//  CJMacro.swift
//  CJCore
//
//  Created by 陈警卫 on 2024-06-11.
//

import Foundation

/// 打印
public func kCJLog<T>(_ message: T, filename: String = #file, funcname: String = #function, linenum: Int = #line) {
#if DEBUG
    let filen = (filename as NSString).lastPathComponent.components(separatedBy: ".").first ?? ""
    
    let dateFormat = DateFormatter()
    dateFormat.dateFormat = "HH:mm:ss:SSSS"
    dateFormat.timeZone = .current
    dateFormat.locale = .current
    let dates = dateFormat.string(from: Date())
    
    let thread = Thread.current.description.components(separatedBy: "number = ").last?.components(separatedBy: ",").first ?? ""

    let prefix = "┌ -----\n[\(thread)][\(filen):\(funcname):\(linenum)]\n\(message)\n\(dates)\n└ -----"
    print(prefix)
#endif
}

/// 全局打印deinit
public func cj_deinit(_ value: Any) {
    kCJLog("\(value)--deinit")
}

/// 获取内存长度
public func cj_sizeof<T>(_ : T) -> Int {
    return (MemoryLayout<T>.size)
}

/// 获取内存长度
public func cj_sizeof<T>(_ : T.Type) -> Int {
    return (MemoryLayout<T>.size)
}

/// 获取内存长度
public func cj_sizeofs<T>(_ values : [T]) -> Int {
    return (MemoryLayout<T>.size * values.count)
}
